Kurento KMS 流媒体服务器 webRTC转rtmp http flv 您所在的位置:网站首页 docker 流媒体服务器 Kurento KMS 流媒体服务器 webRTC转rtmp http flv

Kurento KMS 流媒体服务器 webRTC转rtmp http flv

2024-01-07 17:28| 来源: 网络整理| 查看: 265

mugennsou/http-flv http-flv/README_CN.md at master · mugennsou/http-flv (github.com)

nginx-http-flv-module/README.CN.md at master · winshining/nginx-http-flv-module (github.com)

下载docker镜像: docker pull mugennsou/nginx-http-flv 运行流媒体服务器: docker run --rm -it -p 80:80 -p 1935:1935 mugennsou/nginx-http-flv 往指定的服务器推流 ffmpeg -re -i ~/Videos/b.mp4 -c copy -f flv rtmp://127.0.0.1/demo/stream-1 访问 http://127.0.0.1

Ubuntu安装ffmpeg: sudo apt-get install ffmpeg

 

srs流媒体服务器

推流:

RTMP使用Frame,即帧级别对象。 RTC使用RTP,即包级别对象,Video Frame可能会包含多个RTP packet。 RTMP转RTC,使用Bridger,这样使RTMP和RTC的逻辑相对独立。 RTC下行NACK和PLI都支持,上行NACK还未支持,能跑通了。

详细改动可以参考:c768a8c...3cb797d

 

https://blog.csdn.net/lixiang987654321/article/details/108714690

webRTC推流 视频教学:https://www.bilibili.com/video/av800024876/

SRS文档:

https://github.com/ossrs/srs/tree/4.0releasehttps://github.com/ossrs/srs/wiki/v4_CN_Home

源码编译:

国内: 1, 源码克隆 git clone https://gitee.com/winlinvip/srs.oschina.git srs && cd srs/trunk && git remote set-url origin https://github.com/ossrs/srs.git && git pull 2, 转到最新4.0开发版,因要使用webRTC git checkout 4.0release 3,–rtc=on 默认 ./configure --with-hls --with-ssl --with-http-server --with-http-callback --with-http-api --with-ingest --with-stream-caster && make

成功后显示:

Generate Makefile Configure ok! Configure summary: --x86-x64 --with-hls --with-ssl --with-http-server --with-http-callback --with-http-api --with-ingest --with-stream-caster --prefix=/usr/local/srs --hls=on --hds=off --dvr=on --ssl=on --https=on --ssl-1-0=off --sys-ssl=off --transcode=on --ingest=on --stat=on --http-callback=on --http-server=on --stream-caster=on --http-api=on --utest=off --srt=off --rtc=on --simulator=off --gb28181=off --cxx11=off --cxx14=off --ffmpeg-fit=on --nasm=off --srtp-nasm=off --sendmmsg=off --clean=on --gperf=off --gmc=off --gmd=off --gmp=off --gcp=off --gprof=off --log-trace --cc=gcc --cxx=g++ --ar=ar --ld=ld --randlib=randlib HLS is enabled. Experiment: StreamCaster is enabled. Warning: HDS is disabled. Warning: SRT is disabled. Experiment: RTC is enabled. https://github.com/ossrs/srs/issues/307 Experiment: HTTPS is enabled. https://github.com/ossrs/srs/issues/1657 DVR is enabled. RTMP complex handshake is enabled The transcoding is enabled The ingesting is enabled. The http-callback is enabled Embeded HTTP server for HTTP-FLV/HLS is enabled. The HTTP API is enabled Note: The utests are disabled. Note: The gperf(tcmalloc) is disabled. Note: The gmc(gperf memory check) is disabled. Note: The gmd(gperf memory defense) is disabled. Note: The gmp(gperf memory profile) is disabled. Note: The gcp(gperf cpu profile) is disabled. Note: The gprof(GNU profile tool) is disabled. Note: The valgrind is disabled. Enable module: modules/hls-ingester Enable module: modules/mp4-parser Do full cleanup, you can disable it by: --clean=off You can clean each some components, see make help You can run 3rdparty applications: " python ./research/api-server/server.py 8085 " to start the api-server You can build SRS: " make " to build the srs(simple rtmp server). " make help " to get the usage of make View Code make _default make[1]: Entering directory '/home/zhibin/dev/srs/trunk' Build the srs(simple rtmp server) over ST(state-threads) make -f objs/Makefile srs make[2]: Entering directory '/home/zhibin/dev/srs/trunk' make[2]: Nothing to be done for 'srs'. make[2]: Leaving directory '/home/zhibin/dev/srs/trunk' Ignore utest for it's disabled. Build the srs_hls_ingester over SRS make -f objs/Makefile srs_hls_ingester make[2]: Entering directory '/home/zhibin/dev/srs/trunk' make[2]: Nothing to be done for 'srs_hls_ingester'. make[2]: Leaving directory '/home/zhibin/dev/srs/trunk' Build the srs_mp4_parser over SRS make -f objs/Makefile srs_mp4_parser make[2]: Entering directory '/home/zhibin/dev/srs/trunk' make[2]: Nothing to be done for 'srs_mp4_parser'. make[2]: Leaving directory '/home/zhibin/dev/srs/trunk' The build summary: +------------------------------------------------------------------------------------ For SRS benchmark, gperf, gprof and valgrind, please read: http://blog.csdn.net/win_lin/article/details/53503869 +------------------------------------------------------------------------------------ |The main server usage: ./objs/srs -c conf/srs.conf, start the srs server | About HLS, please read https://github.com/ossrs/srs/wiki/v2_CN_DeliveryHLS | About DVR, please read https://github.com/ossrs/srs/wiki/v3_CN_DVR | About SSL, please read https://github.com/ossrs/srs/wiki/v1_CN_RTMPHandshake | About transcoding, please read https://github.com/ossrs/srs/wiki/v3_CN_FFMPEG | About ingester, please read https://github.com/ossrs/srs/wiki/v1_CN_Ingest | About http-callback, please read https://github.com/ossrs/srs/wiki/v3_CN_HTTPCallback | Aoubt http-server, please read https://github.com/ossrs/srs/wiki/v2_CN_HTTPServer | About http-api, please read https://github.com/ossrs/srs/wiki/v3_CN_HTTPApi | About stream-caster, please read https://github.com/ossrs/srs/wiki/v2_CN_Streamer | (Disabled) About VALGRIND, please read https://github.com/ossrs/state-threads/issues/2 +------------------------------------------------------------------------------------ binaries, please read https://github.com/ossrs/srs/wiki/v2_CN_Build You can: ./objs/srs -c conf/srs.conf to start the srs server, with config conf/srs.conf. make[1]: Leaving directory '/home/zhibin/dev/srs/trunk' View Code

运行 输出webRTC(参考:https://github.com/ossrs/srs/issues/307):

./objs/srs -c conf/rtc.conf [2020-12-14 16:57:41.108][Trace][38868][34doo9ww] XCORE-SRS/4.0.56(Leo) [2020-12-14 16:57:41.108][Trace][38868][34doo9ww] config parse complete [2020-12-14 16:57:41.108][Trace][38868][34doo9ww] you can check log by: tail -f ./objs/srs.log (@see https://github.com/ossrs/srs/wiki/v1_CN_SrsLog) [2020-12-14 16:57:41.108][Trace][38868][34doo9ww] please check SRS by: ./etc/init.d/srs status

用FFMPEG或OBS推送RTMP流到服务器:

  用rtmp来传输flv流:

ffmpeg -re -i doc/source.200kbps.768x320.flv -c copy \ -f flv -y rtmp://192.168.1.3/live/livestream

obs的界面设置,后面的串流密钥a.flv是要接到url就可以观看了。

播放器中url写: http://localhost:8000/live/a.flv

 flv播放器h5源码:

if (flvjs.isSupported()) { var videoElement = document.getElementById('videoElement'); var flvPlayer = flvjs.createPlayer({ type: 'flv', url:'http://localhost:8000/live/a.flv' }); flvPlayer.attachMediaElement(videoElement); flvPlayer.load(); flvPlayer.play(); } View Code 成功时显示: 推摄像头通过rtmp推流 ffmpeg -f dshow -i video="HD Camera":audio="麦克风阵列 (Realtek(R) Audio)" -vcodec libx264 -x264opts "bframes=0" -r 25 -g 25 -preset:v ultrafast -tune:v zerolatency -codec:a aac -ac 2 -ar 44100 -f flv rtmp://192.168.50.150:1935/live/1 View Code

webRTC推流:https://ossrs.net/players/srs_player.html 这个页面都有包括播放,推流。 

推流拉流工具ffmpeg,obs界面 方法:https://cloud.tencent.com/developer/article/1505068

sudo add-apt-repository ppa:obsproject/obs-studio sudo apt update sudo apt install obs-studio

 

可播放的流地址:

rtmp://127.0.0.1/live/livestream webrtc://127.0.0.1/live/livestream http flv地址是:  http://192.168.16.133:8080/live/livestream.flv 对于http flv需要在conf/rtc.conf中添加 http remux: vhost __defaultVhost__ { rtc { enabled on; bframe discard; } http_remux { enabled on; mount [vhost]/[app]/[stream].flv; } } View Code

 

播放验证,用网页的播放器直接播放:https://ossrs.net/players/srs_player.html 输入网址即可播放 webrtc rtmp等

 

 go实现的webrtc。

开源的monibuca,简洁和可插拔,架构不错:http://docs.monibuca.com/

首先我们知道,Rtmp是一种客户端到服务端的技术,Peer to Server。WebRTC是一种客户端到客户端的技术,Peer to Peer。

Rtmp通过一个TCP连接,向服务端发送或接收连接信息,媒体数据。

WebRTC先使用ICE技术连接STUN/TURN,得到自己的连接信息。再绑定音视频设备获取媒体信息,拼装为SDP信令。两个客户端通过任意方式交换信令,建立客户端直接的连接,再使用RTP发送和接收媒体数据。

如果一个服务端实现了WebRTC客户端的能力,那么它也可以被认为是一个Peer,与用户浏览器的WebRTC客户端创建连接,获得客户端推送过来的媒体数据,就完成了Peer to Server的转换。

需要定义信令交换的方式,web编程当然最简单的就是WebSocket了,定义了一个URL格式wss://serverip:port/live/stream.rtc 这种格式和RTMP,HTTP-FLV等相互通用。必须是wss,因为现在的浏览器对webrtc访问摄像头,测试用localhost可以不用ssl。信令交换后,客户端创建了和服务端的udp连接,并源源不断的发送H.264+Opus的rtp包。目前客户端能使用的视频编码是vp8,vp9,h264,音频有PCMA,Opus,不会有AAC,因此我们还需要定义flv封装Opus。Opus和AAC类似,我们定义id为13。这样实现rtmp播放客户端的时候,加入opus解码能力和flv负载opus的能力,就可以播放啦。服务端将Opus直接转码为AAC todo。

webRTC不是localhost时需要https,可以做个代理实现:

https://github.com/ossrs/go-oryx/tree/develop/httpx-static

文档都在上面的链接中,做为代理的命令:

go get github.com/ossrs/go-oryx/httpx-static && cd $GOPATH/src/github.com/ossrs/go-oryx/httpx-static && openssl genrsa -out server.key 2048 && subj="/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=me.org" && openssl req -new -x509 -key server.key -out server.crt -days 365 -subj $subj && $GOPATH/bin/httpx-static -https 8443 -root `pwd`/html -proxy http://ossrs.net:1985/api/v1

windows上启动,https端口在8443

set PATH=%gopath%\bin;E:\dev\TASSL-1.1.1b-master\apps;%PATH%; cd C:\Users\zhibin\go\src\github.com\ossrs\go-oryx\httpx-static rem openssl genrsa -out server.key 2048 rem openssl req -new -x509 -key server.key -out server.crt -days 365 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=me.org" rem httpx-static -t 8088 -s 8443 -r ./html -p http://localhost:8081 -d 192.168.50.206 -k server.key -c server.crt

 

WebRTC 研究系列 二、打通webrtc与rtmp

pion/webrtc  go语言的。

https://github.com/pion/example-webrtc-applications/tree/master/twitch 一个利用ffmpeg转发到rtmp的示例

 

 

WebRTC video stream broadcastwith conversion to RTMP WebRTC broadcast with republishing as RTMP

WebRTC as RTMP republishing

商用的:

1,http://bashell.nodemedia.cn/archives/webrtc-research-series-2-get-through-webrtc-and-rtmp.html

WebRTC推流--ShowDoc (nodemedia.cn) 

2,https://flashphoner.com/webrtc-as-rtmp-re-publishing/

 

带你吃透RTMP SRS 代码分析 https://blog.csdn.net/ManagerUser/article/details/73840130/ srs部署/webrtc拉流 webrtc 资源 WebRTC for the Curious


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有